#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const int N = 100005;
int n, m, A[N], a[N], len, X[4], lg[N], mx[18][N * 2], vis[N]; LL val[18][N * 2]; char s[18][N];
struct qry { int k, id; } q[N];
int main() {
    freopen("arena.in", "r", stdin);
    freopen("arena.out", "w", stdout);
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) scanf("%d", &A[i]);
    for (int i = 1; i <= m; i++) scanf("%d", &q[i].k), vis[q[i].k] = i;
    for (int i = 2; i <= n; i++) lg[i] = lg[i + 1 >> 1] + 1;
    for (int i = 1; i <= lg[n]; i++) scanf("%s", s[i] + 1);
    int T; scanf("%d", &T);
    while (T--) {
        for (int i = 0; i < 4; i++) scanf("%d", &X[i]);
        for (int i = 1; i <= n; i++) a[i] = A[i] ^ X[i & 3];
        long long ans = 0;
        for (int i = 1; i <= n; i++) {
            int pos = i, p = i; mx[0][i] = a[i], val[0][i] = i;
            for (int j = 1; j <= lg[i]; j++) {
                int now = (pos + 1) / 2, l, r;
                if (pos & 1) l = pos, r = pos + 1;
                else l = pos - 1, r = pos;
                char ch = s[j][r];
                if (pos & 1) {
                    if (mx[j - 1][l] >= j)
                        val[j][now] = val[j - 1][l], mx[j][now] = val[j - 1][l];
                    else
                        val[j][now] = (((p + 1) + (p + (1 << j - 1))) * (1 << j - 1) / 2), mx[j][now] = p + 1;
                    p += 1 << j - 1;
                } else {
                    if (mx[j - 1][l] >= j)
                        val[j][now] = val[j - 1][l], mx[j][now] = val[j - 1][l];
                    else
                        val[j][now] = val[j - 1][r], mx[j][now] = val[j - 1][r];                    
                }
                pos = now;
            }
            if (vis[i]) ans ^= vis[i] * 1ll * val[lg[i]][1];
        } printf("%lld\n", ans);
    }
    return 0;
}